


import socket
import serial
import sys

TCP_IP = socket.gethostbyname(socket.gethostname())
TCP_PORT = 1337
BUFFER_SIZE = 1024  # Normally 1024, but we want fast respoe

port = "/dev/ttyUSB0"

ser = serial.Serial(port,57600,timeout=1)


ser.open()
if ser.isOpen():
       
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind((TCP_IP, TCP_PORT))
        s.listen(1)
   
        conn, addr = s.accept()
        print 'Connection address:', addr
        while 1:
                data = conn.recv(BUFFER_SIZE)
                if not data: break
                #print "received data:", data
                #conn.send(data)  # echo
                ser.write(data)
                print ser.read(ser.inWaiting())
        conn.close()

